const Goods = require('../models/Goods.js')

class GoodsCtl {
    async find(ctx) {

    }

    async create(ctx) {
        ctx.verifyParams({
            productId: {type: 'string', required: true},
            productName: {type: 'string', required: true},
            salePrice: {type: 'number', required: true},
            productImage: {type: 'string', required: false},
            checked: {type: 'string', required: false},
            productNum: {type: 'number', required: true},
            productCount: {type: 'number', required: true},
        })
        const { productId } = ctx.request.body
        const repeatedGood = await Goods.findOne(productId)
        if(repeatedGood) {
            return ctx.throw(409, '此商品ud重复')
        }
        const good = Goods.create(ctx.request.body)
        ctx.body = good
    }

    async sort() {

    }

    async region() {

    }

    async paging() {

    }

    async comprehensive() {

    }
}

module.exports = new GoodsCtl()